﻿@{
    ViewBag.Title = "我发起的流程";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@section HeadIncluder 
{ 
    <link href='@Url.Content("~/Content/public.css")'  type="text/css" rel="stylesheet" />
    <link href='@Url.Content("~/Content/con_style.css")'  type="text/css" rel="stylesheet" />
     <link rel="stylesheet" type="text/css" href=@Url.Content("~/Scripts/skins/default.css")   />
    <script type="text/javascript" src=@Url.Content("~/Scripts/lhgdialog.min.js")> </script>
 
}
<div class="content" onkeydown="EnterClick(event.keyCode)">
    <div class="ss_box list_tble" style="margin-top: 20px;">
        <div class="s_box1">
          <table class="s_tble ">
                <tr>
                    <td   class="aR">流程标题/序号:</td>
                    <td class="aL" colspan="2">
                        <input id="txtAppName" type="text" name="AppName" /></td>
                    <td  class="aR">单据类型:</td>
                    <td class="aL" colspan="2"  >
                        <select id="dpProcessList" name="ProcessList">
                            <option value="" selected="selected">全部</option>
                            @{
                                IList<FCDB.Entity.WfProcess> list = ViewBag.ProcessList as IList<FCDB.Entity.WfProcess>;
                                foreach (var item in list)
                                {
                                <option value="@item.ProcessGUID"   >@item.ProcessName</option>
                                }
                            }
                        </select>
                    </td>
                    <td  class="aR">发送时间:</td>
                    <td class="aL">
                        <input id="txtStartDate" type="text" />到<input id="txtEndDate" type="text" />
                    </td>
                    
                </tr>
                <tr>
                     <td class="aR">创建人:</td>
                    <td class="aL" > 
                        <input id="txtUsersName" type="text" name="UsersName" disabled="disabled"  style="width:120px;" />
                        <input type="hidden" id="txtUsersID" name="txtUsersID" />
                    </td>
                    <td class="aL"><span class="btn_s btn_c1"><a href="javascript:void(0)" onclick="addUsers()">添加</a></span></td>
                    <td class="aR">创建部门:</td> 
                    <td class="aL">
                        <input id="txtUsersDepartment" type="text" name="UsersDepartment" disabled="disabled"  style="width:120px;" />
                        <input type="hidden" id="txUsersDepartmentID" name="txtUsersDepartmentID" />
                    </td>
                    <td><span class="btn_s btn_c1"  >
                            <a href="javascript:void(0)" onclick="SelectDeparment(txUsersDepartmentID,txtUsersDepartment)">选择部门</a></span></td>
                    <td class="aL"   colspan="2"><span class="btn_s btn_c1" style="margin-left: 4px;"><a href="javascript:void(0)" onclick="onRefresh()">查找</a></span></td>
                </tr>
            </table>
        </div>
    </div>
</div>
 <div id="container" style="margin-right: 10px;">
        <div id="divGrid" style="width: 100%; height: 100%;">
            <table id="grid">
                <tr>
                    <th>序号</th>
                    <th>流程实例名称</th>
                    <th>流程名称</th>
                    <th>流程状态</th>
                    <th>当前步骤</th>
                    <th>接收人</th>
                    <th>发送人</th>
                    <th>创建时间</th>
                    @*<th  >操作</th>*@
                </tr>
            </table>
            <a></a>
        </div>
    </div>
    <script id="rowTemplate" type="text/x-kendo-tmpl">
        <tr>
           <td><a href="javascript:void(0)" onclick="onProcessClick('#: AppInstanceID #','#: AppName #','#: ProcessGUID #')" >#: AppInstanceID #</a></td> 
            <td><a href="javascript:void(0)" onclick="onProcessClick('#: AppInstanceID #','#: AppName #','#: ProcessGUID #')" >#: AppName #</a></td>
           <td>#: ProcessName #</td>
           <td>#: ProcessState #</td>
           <td>#: ActivityName #</td> 
           <td>#: ReceiveUserName #</td> 
           <td>#: SendUserName #</td> 
           <td>#: CreatedDateTime#</td> 
         
        </tr>
</script>
 <script type="text/javascript" >
     function onProcessClick(AppInstanceID, AppName, ProcessGUID) {
         var url = '@Url.Action("ViewProccessInstance")' + "?AppInstanceID=" + AppInstanceID + "&&AppName=" + AppName + "&&ProcessGUID=" + ProcessGUID;
         var width = screen.availWidth * 0.8;
         var top = screen.availWidth * 0.05;
         var left = screen.availWidth * 0.1;
         var height = screen.availHeight * 0.8;
         window.open(url, "", "width=" + width + "px, height=" + height + "px, top=" + top + "px, left=" + left + "px");

     }   
     function DeleteMyProcessInstance(AppInstanceID) {
         var url = '@Url.Action("DeleteMyProcessInstance")' + '?AppInstanceID=' + AppInstanceID;
         $.post(url, function (data) {
             if (data.Status == 1) {
                 onRefresh();
             } else {
                 alert("流程删除失败！请联系系统管理员");
             }
         });
     }
     function EnterClick(va) {
         if (va == 13) {
             onRefresh()
         }
     }
     function onClear() {
         $("#frm").reset();
     }
     function onRefresh() {
         var grid = $("#grid").data("kendoGrid");
         grid.dataSource.read();
     }
     function loadData() {
         $("#grid").kendoGrid({
             dataSource: {
                 serverPaging: true,
                 serverSorting: true,
                 pageSize: 10,
                 transport: {
                     read: {
                         url: '@Url.Action("Index")',
                         type: "POST",
                         dataType: "json",
                         data: {
                             dtStart: function () {
                                 return $("#txtStartDate").val();
                             },
                             dtEnd: function () {
                                 return $("#txtEndDate").val();
                             },
                             keyword: function () {
                                 return $("#txtAppName").val();
                             },
                             ProcessGUID: function () {
                                 return $("#dpProcessList").val();
                             }
                         }
                     }
                 },
                 schema: {
                     model: {
                         fields: {
                             CreatedDateTime: { type: "date" }
                         }
                     },
                     //取出資料陣列
                     data: function (d) { return d.Data; },
                     //取出資料總筆數(計算頁數用)
                     total: function (d) { return d.TotalCount; }
                 }
             },
             height: 600,
             scrollable: {
                 virtual: true
             },
             pageable: {
                 refresh: true,
                 pageSizes: true
             },
             dataBinding: function (e) {
                 for (var i = 0; i < e.items.length; i++) {
                     switch (e.items[i].ProcessState) {
                         case 0:
                             e.items[i].ProcessState = "未启动";
                             break;
                         case 1:
                             e.items[i].ProcessState = "准备";
                             break;
                         case 2:
                             e.items[i].ProcessState = "流转中";
                             break;
                         case 4:
                             e.items[i].ProcessState = "结束";
                             break;
                         case 8:
                             e.items[i].ProcessState = "挂起";
                             break;
                         case 16:
                             e.items[i].ProcessState = "取消";
                             break;
                         case 32:
                             e.items[i].ProcessState = "终止";
                             break;

                     }
                     e.items[i].CreatedDateTime = company(e.items[i].CreatedDateTime);
                     //if (e.items[i].IsCanDelete == false) {
                     //    e.items[i].IsCanDelete = 'style="display:none"';
                     //}
                 }
             },
             rowTemplate: kendo.template($("#rowTemplate").html())
         });
     }

     $(function () {
         loadData();
         $("#txtStartDate").kendoDatePicker({ format: "yyyy-MM-dd" });
         $("#txtEndDate").kendoDatePicker({ format: "yyyy-MM-dd" });
     });
     function company(CreatedDateTime) {
         var now = new Date(CreatedDateTime);

         var year = now.getFullYear();       //年
         var month = now.getMonth() + 1;     //月
         var day = now.getDate();            //日

         var hh = now.getHours();            //时
         var mm = now.getMinutes();          //分

         var clock = year + "-";

         if (month < 10)
             clock += "0";
         clock += month + "-";

         if (day < 10)
             clock += "0";

         clock += day + " ";

         if (hh < 10)
             clock += "0";

         clock += hh + ":";
         if (mm < 10) clock += '0';
         clock += mm;
         return clock;
     }
 </script>
